<template>
  <a-card :bordered="false">
    <a-form layout="inline">
      <a-form-item label="请选择服务器导出路径">
        <a-select v-model="path" style="width: 300px">
          <a-select-option value="C:/BackupDatabase"> C:/BackupDatabase </a-select-option>
          <a-select-option value="D:/BackupDatabase"> D:/BackupDatabase </a-select-option>
          <a-select-option value="E:/BackupDatabase"> E:/BackupDatabase</a-select-option>
          <a-select-option value="F:/BackupDatabase"> F:/BackupDatabase </a-select-option>
          <a-select-option value="G:/BackupDatabase"> G:/BackupDatabase </a-select-option>
          <a-select-option value="H:/BackupDatabase"> H:/BackupDatabase </a-select-option>
          <a-select-option value="I:/BackupDatabase"> I:/BackupDatabase </a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item>
        <a-button type="primary" html-type="submit" @click="getBackUpData()"> 提交 </a-button>
      </a-form-item>
      <a-form-item>
        <a-button type="primary" :disabled="downloadButton" html-type="submit" @click="downloadFiles()"> 下载 </a-button>
      </a-form-item>
    </a-form>
    <div style="margin-top: 80px">
      <a-steps :current="stepCurrentNum">
        <a-step title="Start" description="选择服务器导出路径" />
        <a-step title="Download" description="可下载到本地">
          <a-icon slot="icon" v-if="showLoading" type="loading" />
        </a-step>
        <a-step title="End" description="下载完毕"></a-step>
      </a-steps>
    </div>
  </a-card>
</template>

<script>
import { getAction } from '@/api/manage'
import { postAction } from '@/api/manage'
import { downloadFile } from '@/api/manage'
import { formatCurrentDate } from '../../utils/util'
export default {
  name: 'BackupDatabase',
  components: {},
  data() {
    return {
      showLoading: false,
      path: null,
      stepCurrentNum: 0,
      downloadButton: true,
      downloadPath: '',
      url: {
        backupDatabases: '/dommanage/dcFileCatalogueMain/backupDatabases',
        downloadDatabases: '/dommanage/dcFileCatalogueMain/downloadDatabases',
      },
    }
  },
  created() {},
  computed: {},
  methods: {
    getBackUpData() {
      this.showLoading = true
      if (!this.path) {
        return this.$message.error('路径不能为空！')
      }
      getAction(this.url.backupDatabases, {
        path: this.path,
      }).then((res) => {
        if (res.success) {
          this.downloadPath=res.result
          this.stepCurrentNum = 1
          this.downloadButton = false
          this.showLoading = false
        } else {
          this.showLoading = false
          return this.$message.error(res.message)
        }
      })
      this.visibleRead = true
    },
    downloadFiles(){
      var fileName=formatCurrentDate('yyyy-MM-dd-hh-mm-ss');
      downloadFile(this.url.downloadDatabases,fileName+'.sql',{
        path:this.downloadPath
      });
      this.stepCurrentNum = 3
    }
   

  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>